package cn.iocoder.yudao.module.moa.service.ccapply;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.moa.controller.admin.ccapply.vo.*;
import cn.iocoder.yudao.module.moa.dal.dataobject.ccapply.CcApplyDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.moa.dal.mysql.ccapply.CcApplyMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;


/**
 * 出差申请 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class CcApplyServiceImpl implements CcApplyService {

    @Resource
    private CcApplyMapper ccApplyMapper;

    @Override
    public Long createCcApply(CcApplySaveReqVO createReqVO) {
        // 插入
        CcApplyDO ccApply = BeanUtils.toBean(createReqVO, CcApplyDO.class);
        ccApplyMapper.insert(ccApply);
        // 返回
        return ccApply.getId();
    }

    @Override
    public void updateCcApply(CcApplySaveReqVO updateReqVO) {
        // 校验存在
        validateCcApplyExists(updateReqVO.getId());
        // 更新
        CcApplyDO updateObj = BeanUtils.toBean(updateReqVO, CcApplyDO.class);
        ccApplyMapper.updateById(updateObj);
    }

    @Override
    public void deleteCcApply(Long id) {
        // 校验存在
        validateCcApplyExists(id);
        // 删除
        ccApplyMapper.deleteById(id);
    }

    private void validateCcApplyExists(Long id) {
        if (ccApplyMapper.selectById(id) == null) {
        }
    }

    @Override
    public CcApplyDO getCcApply(Long id) {
        return ccApplyMapper.selectById(id);
    }

    @Override
    public PageResult<CcApplyDO> getCcApplyPage(CcApplyPageReqVO pageReqVO) {
        return ccApplyMapper.selectPage(pageReqVO);
    }

}
